package com.yhcui.monitor.startup;

import com.yhcui.monitor.logic.MonitorLogic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class StartUp  implements ApplicationRunner {

    @Autowired
    private MonitorLogic monitorLogic;

    private volatile boolean state;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("start up begin");
        synchronized (StartUp.class) {
            if (state) {
                log.info("server started");
                return;
            }
            monitorLogic.init();
            monitorLogic.start();
            state = true;

        }
        log.info("start up end");
    }

}
